<?php
class CmsInstallController extends Controller
{
    public function GetConfig()
    {
        return CmsConfig::GetInstance();
    }

    protected function GetLayout()
    {
        return new BlankLayout();
    }

    public function Index()
    {
        if (RequestHandler::IsExisted('connection'))
        {
            $this->DoInstall(RequestHandler::Get('connection'));
            RequestHandler::Redirect($this->config->URL);
        }
        $this->config->AddCss('install');
        return $this->Render();
    }

    protected function DoInstall($connection)
    {
        $connection['id'] = 'default';
        $connection['isdefault'] = 1;
        ConnectionModel::GetInstance()->Insert($connection);
        $this->DoInstallDB();
    }

    protected function DoInstallDB()
    {
        $connectionId = ConnectionModel::GetDefaultId();
        $connection = MysqlAdapter::Get($connectionId);
        $connection->ExecuteFile(AppConfig::GetInstance()->DIR_DATA.DS.'cms_install.sql');
    }
}
?>